<template>
  <div style="height: 143px;">
    <div class='banner'>
      <div class='imgbox'>
        <transition name='fadein'>
          <img v-if='index === curIndex' v-for='(item, index) in advertList' :key='index' v-lazy='item.adPath ? item.adPath : ""' alt="" />
          <!-- <div v-if='index === curIndex' v-for='(item, index) in advertList' :key='index'></div> -->
        </transition>
      </div>
      <div class='markbox'>
        <div v-for='(item, index) in advertList' :key='index' class='mark' @click='curIndex = index' :class='{active:index === curIndex}'>
          <span></span>
        </div>
      </div>
      <button class='edit' @click='$router.push(`/advertMange/add?three=${$route.query.three}&id=${advertList[curIndex].id}&terminal=${terminal}`)'>编辑</button>
      <button class='delate' @click='delPanel = true'>删除</button>
    </div>

    <!-- 删除广告 -->
    <w-panel-fixed-wrap v-model="delPanel"  :panel-title="true" title="删除广告" :width="`260px`" :height="`200px`" @on-confirm='delOption'>
      <div class="panel-classify">
        是否确认删除该广告
      </div>
    </w-panel-fixed-wrap>
  </div>
</template>

<script>
import { apiDecorateMange } from 'js/api'
import { mapGetters } from 'vuex'

export default {
  props: {
    advertList: {
      type: Array
    },
    terminal: String
  },
  data() {
    return {
      curIndex: 0,
      delPanel: false,
      delParams: {
        accessToken: '',
        threeMenuCode: this.$route.query.three || '',
        idList: []
      }
    }
  },
  computed: {
    ...mapGetters(['token'])
  },
  methods: {
    delOption() {
      this.delParams.accessToken = this.token
      this.delParams.idList = [Number(this.advertList[this.curIndex].id)]
      apiDecorateMange.delAdvert(this.delParams).then(data => {
        if (data.code != 200) return
        this.$toast('删除成功', () => {
          this.curIndex = 0
          this.delPanel = false
          this.$emit('refresh')
        })
      })
    }
  }  
}
</script>

<style lang='scss' scoped>
@import '../../../scss/_var.scss';
.banner{
  height: 100%;
  // height: 143px;
  width: 100%;
  color:#aaaaaa;
  position:relative;
  .imgbox{
    width:100%;
    height:100%;
    font-size:0px;
    white-space:nowrap;
    overflow:hidden;
    background: $bg-gray;
    img{
      width:100%;
      height:100%;
      display:inline-block;
      vertical-align: top;
    }
  }
  .markbox{
    position:absolute;
    width: 100%;
    height:20px;
    bottom:6px;
    left:50%;
    transform: translate(-50%,0);
    font-size:0px;
    .mark{
      display:inline-block;
      height:100%;
      width:30px;
      padding:7px 0px;
      margin:0 10px;
      cursor:pointer;
      span{
        display:inline-block;
        width:100%;
        height:100%;
        background: $btn-search;
        border-radius:3px;
      }
      &.active{
        cursor:default;
        span{
          background: $color-main;
          
        }
      }
    }
  }
  .edit,.delate{
    font-size:12px;
    cursor:pointer;
    height:20px;
    width:40px;
    background: $color-main;
    position:absolute;
    line-height:20px;
    text-align:center;
    color:#fff;
    right:10px;
    top:10px;
    border-radius:9px
  }
  .delate{
    right:60px;
    
  }
}
.fadein-enter-active{
  transition: opacity 1.5s
}
.fadein-enter{
  opacity:0
}
.fadein-enter-to{
  opacity:1
}
</style>